package com.billy.ohos.swipe.demo.consumer;


import com.billy.ohos.swipe.SmartSwipe;
import com.billy.ohos.swipe.SwipeConsumer;
import com.billy.ohos.swipe.consumer.AbilityShuttersBackConsumer;
import com.billy.ohos.swipe.demo.BaseAbility;
import com.billy.ohos.swipe.demo.ResourceTable;
import ohos.aafwk.content.Intent;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;

/**
 * demo:
 * @author billy.qi
 */
public class SwipeBackShuttersConsumerAbility extends BaseAbility {

    private SwipeConsumer swipeConsumer;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        ComponentContainer parse = (ComponentContainer) LayoutScatter.getInstance(this)
                .parse(ResourceTable.Layout_ability_with_description, null, false);
        super.setUIContent(parse);
        Text textView = (Text) findComponentById(ResourceTable.Id_description);
        textView.setText(ResourceTable.String_demo_description_AbilityShuttersBackConsumer);
        swipeConsumer = SmartSwipe.wrap(parse)
                .removeAllConsumers()
                .addConsumer(new AbilityShuttersBackConsumer(this))
                .setScrimColor(0x7F000000)
                .enableAllDirections();
    }

    @Override
    public void onBackPressed() {
        if (swipeConsumer != null) {
            swipeConsumer.smoothLeftOpen();
        } else {
            super.onBackPressed();
        }
    }

    @Override
    protected void onLeftTitleBtnClick() {
        if (swipeConsumer != null) {
            swipeConsumer.smoothLeftOpen();
        } else {
            super.onLeftTitleBtnClick();
        }
    }

    @Override
    public int getTitleResId() {
        return ResourceTable.String_demo_ui_AbilityShuttersBackConsumer;
    }
}
